package com.zheng.pvz.view
{
	import com.zheng.pvz.action.GoOnFoot;
	import com.zheng.pvz.data.DataConst;
	import com.zheng.pvz.model.proxy.DisplayProxy;
	import com.zheng.pvz.model.proxy.GameProxy;
	import com.zheng.pvz.model.proxy.PlantProxy;
	import com.zheng.pvz.model.proxy.TileProxy;
	import com.zheng.pvz.model.proxy.ZombiesProxy;
	import com.zheng.pvz.model.vo.PlantVo;
	import com.zheng.pvz.model.vo.TileVo;
	import com.zheng.pvz.model.vo.ZombiesVo;
	import com.zheng.pvz.view.plants.PlantPea;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * 游戏主场景
	 * @author Administrator
	 * 
	 */
	public class GameSprite extends Sprite
	{
		public var bgSprite:Sprite;//背景容器
		public var fgSprite:Sprite;//前景容器
		public var tileSprite:TileContain;//tile容器
		public var elementSprite:ElementSprite;//plant，zombies，shell容器
		
		private var gameProxy:GameProxy;//游戏数据
		
		public function GameSprite(gameProxy:GameProxy)
		{
			this.bgSprite=new Sprite();
			this.fgSprite=new Sprite();
			this.tileSprite=new TileContain(gameProxy.tileProxyArr);
			this.elementSprite=new ElementSprite();
			
			this.addChild(this.bgSprite);
			this.addChild(this.tileSprite);
			this.addChild(this.elementSprite);
			this.addChild(this.fgSprite);
			
			this.gameProxy=gameProxy;
			
			addEvent();
		}
		
		private function addEvent():void{
			//添加元素
			this.gameProxy.addEventListener(GameProxy.ADD_ELEMENT,onAddElement);
		}
		/**
		 * 添加元素
		 * 后期该方法需要再做修改
		 * 元素的总类比较繁多，现在只能根据数据创建三种元素
		 * @param e
		 * 
		 */
		private function onAddElement(e:Event):void{
			var proxy:DisplayProxy=this.gameProxy.tempAddProxyArr.shift();
			if(!proxy)return;
			var type:String=proxy.vo.displayType;
			switch(type){
				case PlantVo.TYPE:
					this.gameProxy.plantProxyArr.push(proxy);
					var plant:PlantPea=new PlantPea(this.elementSprite,PlantProxy(proxy));
					plant.put(); 
					break;
				case TileVo.TYPE:
					this.gameProxy.tileProxyArr.push(proxy);
					var tile:Tile=new Tile(this.tileSprite,TileProxy(proxy));
					tile.put();
					break;
				case ZombiesVo.TYPE:
					this.gameProxy.zombiesProxyArr.push(proxy);
					var zombies:ZombiesClass=new ZombiesClass(this.elementSprite,ZombiesProxy(proxy));
					var goOnFoot:IAction=new GoOnFoot();
					zombies.addAction(goOnFoot);
					zombies.addStatus(DataConst.STATUS_NORMAL,new ZombiesNormal);
					zombies.addStatus(DataConst.STATUS_DEL,new ZombiesMcDel); 
					zombies.put();
					break;
			}
		}
		
	}
}